package com.martian.controller;

import com.martian.common.exception.SysException;
import com.martian.common.wrapper.ResultWrapper;
import com.martian.pojo.form.CommentForm;
import com.martian.pojo.form.CommentLikeForm;
import com.martian.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author martian
 * @version V1.0.0
 * @Description
 * @date 2023-05-01 11:08
 */
@CrossOrigin
@Api(value = "CommentController", tags = {"评论API"})
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Resource
    CommentService commentService;

    @ApiOperation(value = "发表评论", produces = "application/json")
    @PostMapping("/publish")
    public ResultWrapper publishComment(@RequestBody CommentForm commentForm){
        try{
            commentService.publishComment(commentForm);
            return ResultWrapper.success("评论成功");
        }catch (SysException e){
            return ResultWrapper.failure(e.getMessage());
        }
    }
    @ApiOperation(value = "查看评论", produces = "application/json")
    @GetMapping("/visitor/getCommentByMovieId")
    public ResultWrapper getComment(@RequestParam Integer movieId, @RequestParam Integer parentId){
        try{
            return ResultWrapper.successWithData(commentService.getComment(movieId,parentId));
        }catch (SysException e){
            return ResultWrapper.failure(e.getMessage());
        }
    }
    @ApiOperation(value = "查看所有评论", produces = "application/json")
    @GetMapping("/visitor/getAllComments")
    public ResultWrapper getAllComments(@RequestParam Integer page,@RequestParam Integer pageSize){
        try{
            return ResultWrapper.successWithData(commentService.getAllComments(page,pageSize));
        }catch (SysException e){
            return ResultWrapper.failure(e.getMessage());
        }
    }
    @ApiOperation(value = "点赞评论", produces = "application/json")
    @PostMapping("/likeComment")
    public ResultWrapper likeComment(@RequestBody CommentLikeForm commentLikeForm){
        try{
            commentService.likeComment(commentLikeForm);
            return ResultWrapper.success();
        }catch (SysException e){
            return ResultWrapper.failure(e.getMessage());
        }
    }

}
